package demo.proxy.dynamic.cglib;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

// 相当于Aspect
public class PayMethodInterceptor implements MethodInterceptor {
    @Override
    public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
        before();
        Object res = methodProxy.invokeSuper(proxy,args); // 可以直接调用原方法， 无需原对象
        after();
        return res;
    }

    // Before Advice:
    private void before() {
        System.out.println("支付前的操作");
    }
    // After Advice:
    private void after() {
        System.out.println("支付后的操作");
    }
}
